package com.twu.biblioteca;

public class User {

    private final String password;
    private final String name;
    private final String emailAddress;
    private final String phoneNumber;
    private final String username;

    public User(String username, String password, String name, String emailAddress, String phoneNumber) {
        this.username = username;
        this.password = password;
        this.name = name;
        this.emailAddress = emailAddress;
        this.phoneNumber = phoneNumber;
    }

    public boolean matches(String username, String password) {
        return this.username.equals(username) && this.password.equals(password);
    }

    @Override
    public String toString() {
        return String.format("Name: %s\nEmail Address: %s\nPhone number: %s", name, emailAddress, phoneNumber);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        return password.equals(user.password) && username.equals(user.username);

    }

    @Override
    public int hashCode() {
        int result = password.hashCode();
        result = 31 * result + username.hashCode();
        return result;
    }
}
